package com.wolfpire.section.dao.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import com.wolfpire.chapter.dao.ChapterDao;
import com.wolfpire.knowledge.dao.KnowledgeDao;
import com.wolfpire.section.dao.MyDownLoadHistoryDao;
import com.wolfpire.section.dao.SectionDao;
import com.wolfpire.section.dao.StudyHistoryDao;
import com.wolfpire.subject.dao.SubjectDao;
import com.wolfpire.system.common.Constants;
import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.base.dao.impl.BaseHibernateDao;
import com.wolfpire.system.dao.UserDao;
import com.wolfpire.system.model.Chapter;
import com.wolfpire.system.model.DataDict;
import com.wolfpire.system.model.Knowledge;
import com.wolfpire.system.model.MyDownLoadHistory;
import com.wolfpire.system.model.Profession;
import com.wolfpire.system.model.Section;
import com.wolfpire.system.model.StudyHistory;
import com.wolfpire.system.model.Subject;
import com.wolfpire.system.model.User;

@Repository("myDownLoadHistoryDao")
public class MyDownLoadHistoryDaoImpl extends BaseHibernateDao<MyDownLoadHistory, Long> implements MyDownLoadHistoryDao {

	public void saveMyDownLoadHistory(long userId, long sectionId, String filePath) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * 我下载过的资源附件
	 */
	public List<MyDownLoadHistory> findMyDownLoadHistory(long userId, long subjectId) {
		StringBuffer querySql = new StringBuffer();
		List<String> propertyNames = new ArrayList<String>();
		List propertyValues = new ArrayList();
		querySql.append(" select mh.* from t_mydownload_history mh");
		querySql.append(" where mh.user_id = :userId and mh.subject_id = :subjectId order by mh.creat_time");
		propertyNames.add("userId");
		propertyValues.add(userId);
		propertyNames.add("subjectId");
		propertyValues.add(subjectId);
		SQLQuery query = this.createSqlQuery(querySql.toString(), propertyNames, propertyValues);
		query.addEntity(MyDownLoadHistory.class);
		return query.list();
	}

	/**
	 * 查找除用户曾经下载过资源的学科
	 */
	public List<MyDownLoadHistory> findMySubject(long userId) {
		StringBuffer querySql = new StringBuffer();
		List<String> propertyNames = new ArrayList<String>();
		List propertyValues = new ArrayList();
		querySql.append(" select mh.* from t_mydownload_history mh");
		querySql.append(" where mh.user_id = :userId group by mh.subject_id");
		propertyNames.add("userId");
		propertyValues.add(userId);
		SQLQuery query = this.createSqlQuery(querySql.toString(), propertyNames, propertyValues);
		query.addEntity(MyDownLoadHistory.class);
		return query.list();
	}
	
}
